// @algorithm @lc id=80 lang=cpp 
// @title remove-duplicates-from-sorted-array-ii


// @test([1,1,1,2,2,3])=5
// @test([0,0,1,1,1,1,2,3,3])=7
class Solution {
public:
    int removeDuplicates(vector<int>& nums) {
        if(nums.size()<3) return nums.size();
        int j = 2;
        for(int i=2; i<nums.size(); i++)
            if(nums[j-2] != nums[i])
                nums[j++] = nums[i];
        return j;
    }
};